/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package trial.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.ElementCollection;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.persistence.FetchType;
import trial.entity.OrderSet;
import javax.persistence.CascadeType;
/**
 *
 * @author feifei
 */
@Entity
@XmlRootElement
@XmlType(name = "Customer", propOrder = {
    "id",
    "name",
    "customerId",
    "address",
    "bankAccount",
    "allOrders",
    "allShops",
    
})
@Table(name = "TRIAL_CUSTOMER",schema="trial",
        
        uniqueConstraints=@UniqueConstraint(columnNames={""})   
        )
@NamedQueries({
        @NamedQuery(
                     name="Customer.findAll",
                     query="select c from Customer c"
                      ),
        @NamedQuery(
                    name="Customer.findCustomer",
                    query="select c from Customer c where c.customerId=:inputId"
                    )
              }
        )
public class Customer implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String name;
    @Embedded
    private CustomerIdentity customerId;
    @Embedded
    private CustomerAddr address;
    private String bankAccount;

    @OneToMany (mappedBy="customer")
    @ElementCollection(targetClass=OrderSet.class,fetch=FetchType.EAGER)
    private List<OrderSet> allOrders;
    @OneToMany(mappedBy="owner")
    @ElementCollection(targetClass=Shop.class,fetch=FetchType.EAGER)
    private List<Shop> allShops;

    public Customer() {
    }
    
    
    public Customer(String name, CustomerIdentity customerId, CustomerAddr address, String bankAccount) {
        this.name = name;
        this.customerId = customerId;
        this.address = address;
        this.bankAccount = bankAccount;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    
    public CustomerAddr getAddress() {
        return address;
    }

    public void setAddress(CustomerAddr address) {
        this.address = address;
    }

    public List<OrderSet> getAllOrders() {
        return allOrders;
    }

    public void setAllOrders(List<OrderSet> allOrders) {
        this.allOrders = allOrders;
    }

    public List<Shop> getAllShops() {
        return allShops;
    }

    public void setAllShops(List<Shop> allShops) {
        this.allShops = allShops;
    }

    public String getBankAccount() {
        return bankAccount;
    }

    public void setBankAccount(String bankAccount) {
        this.bankAccount = bankAccount;
    }

    public CustomerIdentity getCustomerId() {
        return customerId;
    }

    public void setCustomerId(CustomerIdentity customerId) {
        this.customerId = customerId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Customer other = (Customer) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 83 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

   
    @Override
    public String toString() {
        return "Customer{" + "id=" + id + ", name=" + name + ", customerId=" + customerId + ", address=" + address + ", bankAccount=" + bankAccount + ", allOrders=" + allOrders + ", allShops=" + allShops + '}';
    }
}
